
/*
 * @Author: xgq
 * @Date: 2020-05-13 11:18:05
 * @LastEditTime: 2020-05-22 10:19:16
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \tuyibo\servers\api\wbms\searchBar.js
 */
var express = require('express');
var searchBar_router = express.Router();
var db = require('../../models');


/**
 * @author: Shihh
 * @description: 获取searchBar列表
 * @param {type} 
 * @return:   
 */

// 获取搜索配置
searchBar_router.get('/getSearchBar', async (req, res) => {
  var [page = 1, pagesize = 30] = [req.query.pageNo, req.query.pageSize]
  let condition = {
    "pagesize": pagesize,
    "page": page
  }
  let search = await db.search_bar.getSearchBar(condition)
  let data = {
    code: 200,
    rows: search
  }
  res.json(data)
})
searchBar_router.get('/getMaxSort', async (req, res) => {
  let sort = await db.search_bar.max('sort').catch(err=>{
    console.log(err)
  })
  res.json(sort)
})


searchBar_router.get('/searchStatus', async (req, res) => {
  let pars = req.query
  let result = await db.search_bar.update({
    'status': pars.status
  }, {
    where: {
      'id': pars.id
    }
  });
  res.json(result)
})

searchBar_router.get('/modifySearchStatus', async (req, res) => {
  let pars = req.query
  let result = await db.search_bar.modifySearchStatus(pars);
  res.json(result)
})

//   添加搜索配置
searchBar_router.post('/addSearchBar', async (req, res) => {
  var from = req.body
  let result = await db.search_bar.addSearchBar(from)
  res.json(result)
})

searchBar_router.post('/deleteSearchBar', async (req, res) => {
  var from = req.body
  let result = await db.search_bar.deleteSearchBar(from)
  res.json(result)
})
// 修改搜索bar
searchBar_router.post('/editSearchBar', async (req, res) => {
  let from = req.body
  let result = await db.search_bar.editSearchBar(from);
  res.json(result)
})

//拖动排序
searchBar_router.post('/searchSort', async (req, res) => {
  //start拖动的目的地
  //end从哪一行开始拖动的
  //start《end从后往前拖动   start》end从前往后拖动
  let result = await db.search_bar.searchSort(req.body.params)
  res.json(result)
})

//获取列表条数，用于排序
searchBar_router.get('/getSearchCount', async (req, res) => {
  let result = await db.search_bar.getSearchCount()
  res.json(result)
})


module.exports = searchBar_router